package com.example.bigfile.common.response;

import lombok.Data;

/**
 * @author Wangx
 * @Title:
 * @Package
 * @Description:
 * @date 2022/9/23 14:37
 */
@Data
public class ResultMsgModel <T>{

    private int code;

    private String msg;

    private T data;

    public ResultMsgModel() {
    }
    public ResultMsgModel(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public ResultMsgModel(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResultMsgModel successMsg(String msg) {
        return success(msg, null);
    }

    public static <T> ResultMsgModel<T> success(T data) {
        return success("操作成功", data);
    }

    public static <T> ResultMsgModel<T> success(String msg, T data) {
        return new ResultMsgModel(ResponseCode.RETURN_SUCCESS, msg, data);
    }

    public static ResultMsgModel error(String msg) {
        return new ResultMsgModel(ResponseCode.RETURN_FAIL, msg, null);
    }

    public static ResultMsgModel error(Integer code, String msg) {
        return new ResultMsgModel(code, msg, null);
    }

    public static <T> ResultMsgModel<T> error(T data) {
        return new ResultMsgModel(ResponseCode.RETURN_FAIL, "操作失败", null);
    }

    public static ResultMsgModel result(boolean is) {
        if (is) {
            return success(is);
        }
        return error(is);
    }

}
